<!-- 基础：4、计算属性 计算setter -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>基础：4、计算属性 计算setter</title>
	<script type="text/javascript" src="https://unpkg.com/vue/dist/vue.js"></script>
</head>
<body>
	<div id="app">
		<p>firstName: <input v-model="firstName"></p>
		<p>lastName: <input v-model="lastName"></p>
		<p>{{ fullName }}</p>		
	</div>

	<script type="text/javascript">
		var vm = new Vue({
			el: '#app',
			data: {
				firstName: 'hu',
				lastName: 'yihao'
			},
			// 对于计算属性，每一个计算值都有一个获取器getter和设置器setter，有了这两个东西就可以获取和设置计算值了
			computed: {
				fullName: {
					// getter
					get: function() {
						return this.firstName + ' ' + this.lastName
					},
					// setter
					set: function(newVal) {
						var names = newVal.split(' ')
						this.firstName = names[0]
						this.lastName = names[names.length - 1]
					}
				}
			}
		})

		// 获取值
		// console.log(vm.fullName)
		// 设置值
		// vm.fullName = 'hello world'
	</script>
</body>
</html>
<!-- 代码均通过测试，有什么纰漏欢迎联系 QQ:1123176978  Wechat:hyhlovehuanong -->
